package com.k.base.jdk.proxy.demo1;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * dynamic proxy
 *
 * @author k
 */
public class CarInvocationHandler implements InvocationHandler {
    private final Car car;
    public CarInvocationHandler(Car car){
        this.car = car;
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object result = null;
        try{
            System.out.println("----- before -----");
            result = method.invoke(car,args);
            System.out.println("----- after -----");
        }catch (Exception e){
            System.out.println("----- Exception -----");
            throw e;
        }
        return result;
    }
}
